package com.taotao.controller;

import com.taotao.pojo.TbItem;
import com.taotao.service.ItemCatService;
import com.taotao.service.ItemService;
import com.taotaotao.common.pojo.EasyUIDataGridResult;
import com.taotaotao.common.pojo.EasyUIZreeResult;
import com.taotaotao.common.pojo.TaotaoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//管理商品信息的controller
@Controller
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemServiceimpl;
    @Autowired
    private ItemCatService itemCatService;
    //分页展示所有商品信息的方法
    @RequestMapping("/list")
    @ResponseBody
    public EasyUIDataGridResult getItemList(Integer rows,Integer page){
        EasyUIDataGridResult itemList = itemServiceimpl.getItemList(page, rows);
        return itemList;
    }
    //查询商品分类的方法
    @RequestMapping("/cat/list")
    @ResponseBody
    public List<EasyUIZreeResult> getZreeNode(@RequestParam(value = "id",defaultValue = "0") Long parentId){
        List<EasyUIZreeResult> zreeNodes = itemCatService.getZreeNode(parentId);
        return zreeNodes;
    }
    //添加商品的方法
    @RequestMapping("/save")
    @ResponseBody
    public TaotaoResult addItem(TbItem item, String desc){
        TaotaoResult result = itemServiceimpl.addItem(item,desc);

        return result;

    }


}
